import * as layoutFetch from '../api/apiLayout'
import {findInArray, getHistory, getState, setState, setStateReducer} from "../util/uitls";
import {effects} from 'dva-no-router/saga'
import {GET_USER_DESIGN_IMAGES, GET_USER_DESIGN_IMAGES1} from "../api/uploadCustomFabric";
import {POST_SHOPCART_ITEMS, PUT_DESIGNS_CUSTOM_FABRIC} from "../api/customFabric";
import {message} from 'antd'

const INIT_STATE = {
    editImageItem: {}
}
const Map = require('lodash.map')
const namespace = 'customFabric'
const MODEL = {
    namespace,
    state: INIT_STATE,
    reducers: {
        setState: setStateReducer
    },
    effects: {
        * init({payload}, {call, put}) {
            var data = yield call(GET_USER_DESIGN_IMAGES1, payload)
            yield setState({editImageItem: data}, true)(namespace)
        },
        * add({payload}, {call, put}) {
            var data1 = yield call(PUT_DESIGNS_CUSTOM_FABRIC, payload)
            if (data1.designItems[0]) {
                payload.designItemId = data1.designItems[0].id
                var data2 = yield call(POST_SHOPCART_ITEMS, payload)
                message.success("加入购入车成功")
            } else {
                message.success("加入购入车失败")
            }

        }
    },
    subscriptions: {
        setup({dispatch, history}) {
        },
    },
};

export default MODEL
